﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Profile;
using System.Data;
using Gift.Model.ENUM;

namespace WebSite.admin.title
{
    public partial class addnewsclass : BaseAdmin
    {


    // Methods
    private void Display(string parentid, string space)
    {
        string sql = "Select * From DB_Newsclass" + " Order By classorder";
        DataTable table = new DataTable();
        table = SQLAccess.GreatDs(sql).Tables[0];
        if (table.Rows.Count > 0)
        {
            foreach (DataRow row in table.Rows)
            {
                if (row["Amount"].ToString() != "0")
                {
                    string str5 = this.Label1.Text;
                    this.Label1.Text = str5 + "<table width='100%' border='0' cellpadding='0' cellspacing='0'><tr><td width=5%><input id='Checkbox1' type='checkbox' name='chk' value=" + row["classid"].ToString() + " /></td><td align=left height=22 width=42%>" + space + "<a href='javascript:open_menu(tr_" + row["classid"].ToString() + ");'>";
                    this.Label1.Text = this.Label1.Text + "" + row["classname"].ToString() + "";
                    this.Label1.Text = this.Label1.Text + "</a></td>";
                    if (row["visible"].ToString() == "True")
                    {
                        this.Label1.Text = this.Label1.Text + "<td width='10%'><a href='newsclass.aspx?action=yess&amp;cid=" + row["classid"].ToString() + "'><img src='../images/yes.gif' border='0' /></a></td>";
                    }
                    else
                    {
                        this.Label1.Text = this.Label1.Text + "<td width='10%'><a href='newsclass.aspx?action=noo&amp;cid=" + row["classid"].ToString() + "'><img src='../images/no.gif' border='0' /></a></td>";
                    }
                    string str6 = this.Label1.Text;
                    this.Label1.Text = str6 + "<td width=12%><input id='Text1' type='text' name='order_" + row["classid"].ToString() + "' size='3' value='" + row["classorder"].ToString() + "' /></td>";
                    this.Label1.Text = this.Label1.Text + "<td width=20%><a href='addnewsclass.aspx?cid=" + row["classid"].ToString() + "'>编辑</a>";
                    if (row["system"].ToString() == "False")
                    {
                        this.Label1.Text = this.Label1.Text + "|<a href='newsclass.aspx?action=del&amp;cid=" + row["classid"].ToString() + "'>移除</a>";
                    }
                    this.Label1.Text = this.Label1.Text + "</td></tr></table>";
                    this.Label1.Text = this.Label1.Text + "<table  width='100%' border='0' cellpadding='0' cellspacing='0'><tr id='tr_" + row["classid"].ToString() + "' style='display:; '><td>";
                    this.Display(row["classid"].ToString(), "&nbsp;&nbsp;" + space);
                    this.Label1.Text = this.Label1.Text + "</td></tr></table>";
                    continue;
                }
                string text = this.Label1.Text;
                this.Label1.Text = text + "<table width='100%' border='0' cellpadding='0' cellspacing='0'><tr><td width=5%><input id='Checkbox1' type='checkbox' name='chk' value=" + row["classid"].ToString() + " /></td><td align=left height=22 width=42%>" + space + "";
                string str8 = this.Label1.Text;
                this.Label1.Text = str8 + "<a href='addnewsclass.aspx?cid=" + row["classid"].ToString() + "&lan=cn'>" + row["classname"].ToString() + "</a>";
                if (row["visible"].ToString() == "True")
                {
                    this.Label1.Text = this.Label1.Text + "<td width='10%'><a href='newsclass.aspx?action=yess&amp;cid=" + row["classid"].ToString() + "'><img src='../images/yes.gif' border='0' /></a></td>";
                }
                else
                {
                    this.Label1.Text = this.Label1.Text + "<td width='10%'><a href='newsclass.aspx?action=noo&amp;cid=" + row["classid"].ToString() + "'><img src='../images/no.gif' border='0' /></a></td>";
                }
                string str9 = this.Label1.Text;
                this.Label1.Text = str9 + "<td width=12%><input id='Text1' type='text' name='order_" + row["classid"].ToString() + "' size='3' value='" + row["classorder"].ToString() + "' /></td>";
                this.Label1.Text = this.Label1.Text + "<td width=20%><a href='addnewsclass.aspx?cid=" + row["classid"].ToString() + "'>编辑</a>";
                if (row["system"].ToString() == "False")
                {
                    this.Label1.Text = this.Label1.Text + "|<a href='newsclass.aspx?action=del&amp;cid=" + row["classid"].ToString() + "'>移除</a>";
                }
                this.Label1.Text = this.Label1.Text + "</td></tr></table>";
            }
        }
        if ((base.Request.QueryString["action"] != null) && (base.Request.QueryString["cid"] != null))
        {
            string str4 = "0";
            str4 = str4 + re.returnnewstype("", "0");
            if (base.Request.QueryString["action"].ToString() == "del")
            {
                SQLAccess.DoSql("delete From DB_Newsclass Where classid in (" + str4 + ")");
                SQLAccess.DoSql("delete From DB_News Where typeid in (" + str4 + ")");
            }
            if (base.Request.QueryString["action"].ToString() == "yes")
            {
                SQLAccess.DoSql("update  DB_Newsclass set ishead=0 Where classid=" + base.Request.QueryString["cid"].ToString() + "");
            }
            if (base.Request.QueryString["action"].ToString() == "no")
            {
                DataTable table2 = SQLAccess.GreatDs("select * from DB_Newsclass where classid=" + base.Request.QueryString["cid"].ToString() + "").Tables[0];
                if (table2.Rows.Count > 0)
                {
                    SQLAccess.DoSql("update  DB_Newsclass set ishead=1 Where classid=" + base.Request.QueryString["cid"].ToString() + "");
                    if (table2.Rows[0]["classlink"].ToString() == "")
                    {
                        base.Response.Write("<script language='javascript'>alert('请输入链接地址！');window.location.href='addnewsclass.aspx?cid=" + base.Request.QueryString["cid"].ToString() + "';</script>");
                        base.Response.End();
                    }
                }
            }
            if (base.Request.QueryString["action"].ToString() == "yess")
            {
                SQLAccess.DoSql("update  DB_Newsclass set visible=0 Where classid=" + base.Request.QueryString["cid"].ToString() + "");
            }
            if (base.Request.QueryString["action"].ToString() == "noo")
            {
                SQLAccess.DoSql("update  DB_Newsclass set visible=1 Where classid=" + base.Request.QueryString["cid"].ToString() + "");
            }
            base.Response.Write("<script language=javascript>window.location.href='newsclass.aspx';</script>");
            base.Response.End();
        }
    }

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        string str = base.Request.Form["chk"];
        if (str.ToString() != "")
        {
            string[] strArray = str.Split(new char[] { ',' });
            for (int i = 0; i <= (strArray.Length - 1); i++)
            {
                if (strArray[i].ToString() != "0")
                {
                    string str2 = base.Request.Form["order_" + strArray[i]];
                    SQLAccess.DoSql("update DB_Newsclass set classorder=" + str2 + "  Where classid =" + strArray[i] + "");
                }
            }
            base.Response.Write("<script language=javascript>alert('更新成功!');window.location.href='newsclass.aspx';</script>");
            base.Response.End();
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
     
        this.ImageButton1.Attributes["onclick"] = "return CheckSelect(chk);";
        if (!base.IsPostBack)
        {
            base.ValidateLoginRule(ERule.AddArticleClass);
            this.Label1.Text = this.Label1.Text + "<table width='100%' border='1' cellpadding='0' cellspacing='0' bordercolor='#E2E7EB'><tr class='title01' bgcolor='#E2E7EB'><td width=5%><input id='Checkbox1' type='checkbox' name='chka' value='0' onClick='SelectCheckBox(chk,this)' /></td><td width=42%>";
            this.Label1.Text = this.Label1.Text + "分类名称";
            this.Label1.Text = this.Label1.Text + "</td><td width=10%>是否显示</td><td width=12%>排序</td><td width=20%>操作</td></tr></table>";
            this.Display("0", "|--");
        }
    }

    // Properties
    protected global_asax ApplicationInstance
    {
        get
        {
            return (global_asax) this.Context.ApplicationInstance;
        }
    }

    protected DefaultProfile Profile
    {
        get
        {
            return (DefaultProfile) this.Context.Profile;
        }
    }

    }
}